<template>
	<view class="container">
		<page-nav class="custom-title" title="帮助反馈" :leftShow="true"> </page-nav>
		<view style="padding-left: 25rpx; padding-right: 25rpx;">
			<view style="padding-top: 20rpx;">问题和意见
				<view style="padding-top: 20rpx;"><u--textarea v-model="content" placeholder="请输入内容"
						count></u--textarea></view>
			</view>

			<view style="padding-top: 20rpx;">相关截图(选填，最多传3张）
				<view style="padding-top: 20rpx;"><u-upload :fileList="fileList5" @afterRead="afterRead"
						@delete="deletePic" name="5" multiple :maxCount="3"></u-upload>
				</view>
			</view>


		</view>
		<view style="padding: 30rpx 30rpx;">
			<u-button style="background-color: #2E69FF; font-weight: 500; margin-bottom: 20rpx;" type="primary">提交</u-button>				 
	    </view>

	</view>
</template>


<script>
	export default {
		data() {
			return {
				content: ``,
				fileList5:[]
			};
		},
		onLoad(){
			console.log("token",uni.getStorageSync('token'))
		},
		methods:{
			// 删除图片
						deletePic(event) {
							this[`fileList${event.name}`].splice(event.index, 1)
						},
						// 新增图片
						async afterRead(event) {
							// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
							let lists = [].concat(event.file)
							let fileListLen = this[`fileList${event.name}`].length
							lists.map((item) => {
								this[`fileList${event.name}`].push({
									...item,
									status: 'uploading',
									message: '上传中'
								})
							})
							for (let i = 0; i < lists.length; i++) {
								const result = await this.uploadFilePromise(lists[i].url)
								let item = this[`fileList${event.name}`][fileListLen]
								this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
									status: 'success',
									message: '',
									url: result
								}))
								fileListLen++
							}
						},
						uploadFilePromise(url) {
							 
							return new Promise((resolve, reject) => {
								let a = uni.uploadFile({ 
									url: 'https://www.xrskfw.com/api/blade-resource/oss/endpoint/put-file', // 仅为示例，非真实的接口地址									 
									filePath: url,
									name: 'file',	
									header: {
										"Content-Type": "multipart/form-data",
										'Authorization':'Basic d3hhcHA6d3hhcHBfc2VjcmV0',
										'Blade-Auth': 'bearer '+uni.getStorageSync('token').content
									},
									formData: {
										 
									},
									success: (res) => {
										setTimeout(() => {
											console.log(res)
											resolve(res.data.data)
										}, 1000)
									}
								});
							})
						},
		}
	};
</script>

<style lang="scss">
	.container {
		padding: 0 0 150rpx;
	}

	.nav-item-img {
		width: 150rpx;
	}
</style>